﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion

#region Usings

using System;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using ScrumTable.Common;
using ScrumTable.Common.Collections;
using ScrumTable.DL.Data.Schema;

#endregion

namespace ScrumTable.BL.DM.DataManagement
{

    /// <summary>
    /// Contains the basic information about a user story.
    /// </summary>
    public class Report : DomainBase
    {
        #region Declarations
        //--------------------------------------------------------------------
        // Declarations
        //--------------------------------------------------------------------

        private DomainCollection<DomainMeta<NamedValue>> _fieldMeta;

        #endregion

        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------

        /// <summary>
        /// Gets a list of all tasks associated to the current user story.
        /// </summary>
        public DomainCollection<DomainMeta<NamedValue>> FieldMeta
        {
            get
            {
                if (_fieldMeta == null)
                {
                    _fieldMeta = new DomainCollection<DomainMeta<NamedValue>>(
                        true,
                        Context,
                        this,
                        ContextInternal.Data.Storage[Schema.MetaSchema]);
                }
                return _fieldMeta;
            }
        }


        /// <summary>
        /// Gets the name of the current domain object. In most cases this
        /// property will contain the domain object title.
        /// </summary>
        public override string Name
        {
            get { return DataObject.GetData(Schema.ReportSchema.Name, string.Empty); }
            set { }
        }

        /// <summary>
        /// Returns the absolute path of the report Uri.
        /// </summary>
        public string Path
        {
            get { return DataObject.GetData(Schema.ReportSchema.Path, string.Empty); }
        }

        /// <summary>
        /// Returns the full qualified path of the report Uri.
        /// </summary>
        public Uri FullPath
        {
            get { return DataObject.GetData<Uri>(Schema.ReportSchema.FullPath); }
        }

        /// <summary>
        /// Gets the parent collection instance.
        /// </summary>
        internal override IDomainCollection ParentCollection
        {
            get { return Parent.SearchCollection<Report>(); }
        }

        /// <summary>
        /// Gets a collection which contains all child collections of the current
        /// domain object.
        /// </summary>
        internal override ICollection ChildCollections { get { return new IDomainCollection[] { FieldMeta }; } }

        /// <summary>
        /// Gets the domain object schema of the current domain object.
        /// </summary>
        protected override SchemaBase DomainSchema { get { return Schema.ReportSchema; } }


        private string PostCommandArguments
        {
            get { return DataObject.GetData(Schema.ReportSchema.PostCommandArguments, string.Empty); }
        }

        #endregion

        #region Constructors / Destructor
        //--------------------------------------------------------------------
        // Constructors / Destructor
        //--------------------------------------------------------------------

        #endregion

        #region Methods
        //--------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------

        /// <summary>
        /// Gets the Post string for a pair list Pair[FieldName, Value]
        /// </summary>
        /// <param name="items">Specifies a list of arguments which should be passed to the post command as query arguments.</param>
        /// <returns>Returns the create post command query string.</returns>
        public string ToPostCommandArguments(IEnumerable<Pair<string, string>> items)
        {
            return UriUtil.CreateQueryString(PostCommandArguments, items);
        }

        /// <summary>
        /// Resets all child collections (IDomainCollection instances) of the
        /// current domain object.
        /// </summary>
        protected override void ResetChildCollections()
        {
            _fieldMeta = null;
        }

        /// <summary>
        /// Initializes the mappings stored in the current instance.
        /// </summary>
        protected override void InitializeMappings()
        {
            base.InitializeMappings();

            PropertySchemaMappings.Add(Schema.ReportSchema.Name, "Name");
            PropertySchemaMappings.Add(Schema.ReportSchema.Path, "Path");
            PropertySchemaMappings.Add(Schema.ReportSchema.FullPath, "FullPath");
            PropertySchemaMappings.Add(Schema.ReportSchema.PostCommandArguments, "PostCommandArguments");
        }

        #endregion

        #region Events
        //--------------------------------------------------------------------
        // Events
        //--------------------------------------------------------------------

        #endregion
    }
}